<!doctype html5>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="edge">
    <title>Mocha Tests</title>
    <link href="../node_modules/mocha/mocha.css" rel="stylesheet" />
</head>
<body>
    <div id="mocha"></div>
    <!--[if IE]>
        <script type="text/javascript" src="http://cdn.bootcss.com/babel-polyfill/6.23.0/polyfill.js"></script>
    <![endif]-->
    <script src="../node_modules/mocha/mocha.js"></script>
    <script src="../node_modules/chai/chai.js"></script>

    <script>
        mocha.setup( 'bdd' )
    </script>
    <script src="./index.build.js"></script>
    <script>
        onload = function () {
            mocha.checkLeaks();
            mocha.globals( [ 'chai', 'define', 'script*' ] );
            var runner = mocha.run();
            var failedTests = [];
            runner.on( 'end', function () {
                window.mochaResults = runner.stats;
                window.mochaResults.reports = failedTests;
            } );
            runner.on( 'fail', logFailure );

            function logFailure( test, err ) {
                var flattenTitles = function ( test ) {
                    var titles = [];
                    while ( test.parent.title ) {
                        titles.push( test.parent.title );
                        test = test.parent;
                    }
                    return titles.reverse();
                };

                failedTests.push( {
                    name: test.title,
                    result: false,
                    message: err.message,
                    stack: err.stack,
                    titles: flattenTitles( test )
                } );
            };
        };
    </script>
</body>
</html>